<template>
    <div class="all">
        <div class="bread">首页>>财务管理>>验证码管理</div>
        <div class="nav">
            <div>
                <el-button  type="primary"  plain @click="dialogVisible = true">添加订单</el-button> 
                <span>发布时间</span>
                <span>车型：    
                     <el-select v-model="value" placeholder="选择车型" style="width: 240px">
                       <el-option
                         v-for="item in options"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value"
                       />
                     </el-select>
                </span>
                <span>关键字<input></span>
                <span>搜索</span>
            </div>
        </div>
        <div class="content">
            <el-table :data="tableData" 
            style="width: 100% ;height:calc(100% - 150px);" 
            >
              <el-table-column fixed prop="code" label="验证码" />
              <el-table-column prop="createtime" label="创建时间"  />
              <el-table-column prop="lastqueryip" label="上次登录" />
              <el-table-column prop="querytimes" label="访问次数" />
              <el-table-column prop="remark" label="提示信息" />
              <el-table-column prop="status" label="状态" />
              <el-table-column prop="type" label="车型" />
              <!-- <el-table-column prop="leixing" label="类型" width="120" />
              <el-table-column prop="riqi" label="日期" width="130" />
              <el-table-column prop="jine" label="金额" width="120" />
              <el-table-column prop="shangchuan" label="上传" width="120" />
              <el-table-column prop="beizhu" label="备注" width="150" /> -->
              <!-- <el-table-column prop="siji" label="时间" width="100" /> -->

              <el-table-column fixed="right" label="操作" width="120">
                <template #default="row" >
                  <el-button link type="primary" size="small" @click.prevent="bianjiClick(row)"
                    >编辑</el-button>
                  <!-- <el-button link type="primary" size="small">删除</el-button> -->
                </template>
              </el-table-column>
            </el-table>
            <!-- <Page :message="total" :messagesize="size" @get-message="getMessage">000</Page> -->
            <div class="page">
              <el-pagination
              v-if="total"
                :page-size="20"
                small
                :background="true"
                layout="total, prev, pager, next"
                :total="total"
                @current-change="sizeChange"
            />
            </div>
        </div>
    </div>

    <!-- 添加记录对话框 -->
     <el-dialog
         v-model="dialogVisible"
         title="添加订单"
         width="500"
         :before-close="handleClose"
         style="text-align:center;padding-top: 10px;"
        
       >
       <!-- 添加记录的表单内容 -->
        <el-form :model="form" label-width="auto" style="max-width: 800px;padding: 0px 40px 40px 40px;">
          <el-form-item inline-message='true' label="车辆类型">
            <el-select v-model="form.chexing" placeholder="选择车辆类型">
              <el-option label="车型1" value="车型1" />
              <el-option label="车型2" value="车型2" />
            </el-select>
          </el-form-item>
          <el-form-item label="车牌号码">
            <el-input v-model="form.carNum" />
          </el-form-item>
          <el-form-item label="车辆名称">
            <el-input v-model="form.carname" />
          </el-form-item>
          <el-form-item label="上牌时间">
            <el-col :span="11">
              <el-date-picker
                v-model="form.shangdate"
                type="date"
                placeholder="选择时间"
                style="width: 100%"
              />
            </el-col>
          </el-form-item>
         <el-form-item label="型号">
            <el-select v-model="form.xinghao" placeholder="选择型号">
              <el-option label="型号a" value="型号a" />
              <el-option label="型号b" value="型号b" />
            </el-select>
          </el-form-item>
          <el-form-item label="车架号">
            <el-input v-model="form.chejiahao" />
          </el-form-item>
          <el-form-item label="发动机号">
            <el-input v-model="form.fadongjihao" />
          </el-form-item>
         <el-form-item label="行驶里程">
            <el-input v-model="form.licheng" />
          </el-form-item>
         <el-form-item label="所处位置">
            <el-input v-model="form.position" />
          </el-form-item>

         <el-form-item label="首次年检日期">
            <el-col :span="11">
              <el-date-picker
                v-model="form.shoucinianjian"
                type="date"
                placeholder="选择时间"
                style="width: 100%"
              />
            </el-col>
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="form.zhuangtai" placeholder="选择状态">
              <el-option label="使用" value="使用" />
              <el-option label="闲置" value="闲置" />
            </el-select>
          </el-form-item>
        <el-form-item label="外调">
            <el-select v-model="form.waidiao" placeholder="选择记录类型">
              <el-option label="是" value="是" />
              <el-option label="否" value="否" />
            </el-select>
          </el-form-item>

        </el-form>

         <template #footer>
           <div class="dialog-footer">
             <el-button @click="dialogVisible = false">取消</el-button>
             <el-button type="primary" @click="dialogVisible = false">
               确认
             </el-button>
           </div>
         </template>
     </el-dialog>
       

    <!-- 编辑记录对话框 -->
     <el-dialog
         v-model="bianjiVisible"
         title="编辑验证码状态"
         width="500"
         :before-close="handleClose"
         style="text-align:center;padding-top: 10px;"
       >
       <!-- 编辑记录的表单内容 -->
        <el-form :model="form1" label-width="auto" style="max-width: 800px;padding: 0px 40px 40px 40px;">
          <el-form-item label="验证码">
            <el-input v-model="form1.code" disabled />
          </el-form-item>
          <el-form-item label="创建时间">
            <el-input v-model="form1.createtime" disabled />
          </el-form-item>
          <el-form-item label="id">
            <el-input v-model="form1.id" disabled />
          </el-form-item>
          <el-form-item label="上次登录">
            <el-input v-model="form1.lastqueryip" disabled />
          </el-form-item>
          <el-form-item label="提示信息">
            <el-input v-model="form1.remark" />
          </el-form-item>
          <!-- <el-form-item label="状态">
            <el-input v-model="form1.status" disabled/>
          </el-form-item> -->
          <el-form-item label="状态">
          <el-select v-model="form1.status" placeholder="选择状态">
              <el-option label="已售" value="已售" />
              <el-option label="待售" value="待售" />
            </el-select>
          </el-form-item>
          <el-form-item label="类型">
            <el-input v-model="form1.type" disabled />
          </el-form-item>
        </el-form>

         <template #footer>
           <div class="dialog-footer">
             <el-button @click="bianjiVisible = false">取消</el-button>
             <el-button type="primary" @click="querenbianji">
               确认
             </el-button>
           </div>
         </template>
     </el-dialog>       
</template>

<script setup>
import { ref, reactive,onMounted } from 'vue'
import {getCodeList,putCode} from "../../api/qrcode"

const loading = ref(true)

const size = ref(20)
const totalPages = ref()

const total = ref()
const count = ref(1)
const sizeChange = (num)=>{
  count.value = num
  getCodeInfo()
}

const tableData = ref([])

const getCodeInfo = ()=>{
    console.log("onMountd生效了")
    getCodeList(count.value,{}).then(res=>{
        console.log(res)
        tableData.value = res.data.data
        total.value = res.data.total
        console.log(total.value)
        // totalPages.value = res.data.totalPages
        size.value = res.data.size
    }).catch(err=>{
        console.log(err)
    })


    // getCarList(count.value,{}).then(res =>{
    //   tableloading.value = false
    //   tableData.value = res.data.content
    //     console.log(tableData.value,'请求回来的')
    //   const imagesBack = res.data.content

    //   total.value = Number(res.data.totalElements)
    //   // total.value = res.data.totalElements || 0
    //   console.log('total = ', total.value)
    //   console.log('total type: ', typeof total.value)

      
    //   console.log(res)
    //   console.log(tableData.value, '修改之后的')
    // }).catch(err =>{
    //   if(err){
    //     ElMessage({
    //          message: '获取数据超时，请刷新页面',
    //          grouping: true,
    //          type: 'warning',
    //          offset:200
    //        })
    //        console.log(err)
    //   }
    // })
}

//翻页组件页数变化
const getMessage = (msg)=>{
  console.log(msg)
  count.value = msg - 1
  getinfo()
}

onMounted(()=>{
    getCodeInfo()
})

// //添加记录对话框开关
// const dialogVisible = ref(false)
// //编辑记录对话框开关
const bianjiVisible = ref(false)

// const value = ref('')

// //车型选择
// const options = [
//     {
//         value: '防撞车',
//         label: '防撞车',
//     },
//     {
//         value: '高空作业车',
//         label: '高空作业车',
//     },
//     {
//         value: '桥梁检测车',
//         label: '桥梁检测车',
//     },
//     {
//         value: '自行走',
//         label: '自行走',
//     }
// ]
// //表格 标题和内容
// const tableData = [
//     {
//         xuhao: '01',
//         dingdanhao: '订单001',
//         chepaihao: '京a001',
//         chejiahao: '车架号001',
//         leixing: '油费',
//         riqi: '2022-10-01',
//         jine: '2000',
//         shangchuan: '',
//         beizhu: '',
//     }
// ]
// // 添加记录的表单内容
// const form = reactive({
//     type: '',
//     chepaihao: '',
//     name: '',
//     date: '',
//     xinghao: '',
//     chejia: '',
//     fadongji: '',
//     licheng: '',
//     position: '',
//     nianjian: '',
//     zhuangtai: '',
//     waidiao: '',
// })

// 编辑记录的表单内容
const form1 = ref()

// // // 编辑车辆记录按钮
// const bianjiClick = (index, data) => {
//     bianjiVisible.value = true
//     console.log(tableData, 'xuhao')
//     console.log(index)
//     console.log(tableData[index])
//     // form1.value = tableData[index]
//     // console.log(form1.value)
//     bianjiVisible.value = true
// }

const bianjiClick = (row) => {
  const {...rowData} = row.row
  form1.value = rowData
  bianjiVisible.value = true
  console.log(rowData)
}

const querenbianji = ()=>{
    loading.value = true
    console.log(form1.value.code,)
    console.log(form1.value.remark)
    console.log(form1.value.status)
    const data = {}
    data.code = form1.value.code
    data.remark = form1.value.remark
    data.status = form1.value.status
    putCode(data).then(res=>{
        loading.value = false
        console.log(res)
        bianjiVisible.value = false
        getCodeInfo()
    }).catch(err=>{
        console.log(err)
    })
}

// const deleteRow = (index) => {
//     console.log(index)
// }

</script>

<style lang="scss" scoped>
.all {
    background-color: #d6d6d6;
    height: 100%;
    overflow: hidden;
    padding-left: 10px;

    .bread {
        height: 30px;
        background-color: #fff;
        margin-bottom: 10px;
    }

    .nav {
        height: 40px;
        background-color: #fff;
        margin-bottom: 10px;
        padding: 5px;

        div {
            span {
                margin: 10px;
                line-height: 40px;
            }
        }
    }

    .content {
        background: #fff;
        height: 100%;
        padding: 5px;
        overflow: hidden;
        .page{
          margin: 10px auto;
        }
    }
}

// 翻页的样式
.example-pagination-block + .example-pagination-block {
  margin-top: 10px;
  text-align: center;
}
.example-pagination-block .example-demonstration {
  margin-bottom: 16px;
}

.example-showcase .el-loading-mask {
  z-index: 99;
}

</style>